<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
		<title>Emploi du temps</title>
		<link href="style.css" rel="stylesheet" type="text/css" />
                 <!--[if lte IE 7]>
                <style type="text/css">
                #joursEtEDT
                {
	             margin-left:-1065px;
                }
                </style>
                <![endif]-->
		<script type="text/javascript" src="javascript/jquery.js"></script>
		<script type="text/javascript" src="javascript/scriptEDT.js"></script>
                <script type="text/javascript">

                  var _gaq = _gaq || [];
                  _gaq.push(['_setAccount', 'UA-34618639-1']);
                  _gaq.push(['_trackPageview']);

                  (function() {
                    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
                  })();

</script>
		<link href="favicon.ico" rel="shortcut icon" />
	</head>

<?php 
	//Chargement de l'ID
	require("connection_mysql.inc.php");
	if (isset($_GET['id']) || isset($_GET['s']))
	{
		if (isset($_GET['s'])){
			//echo "SELECT id from section where alias = '".$_GET['s']."';";
			$donneesId = mysql_query("SELECT id from section where alias = '".$_GET['s']."';") or die(mysql_error());
			if ($resultId = mysql_fetch_array($donneesId)){
				$id = $resultId['id'];
				//echo "test ID : $id";
			}
		}else{
			$id = $_GET['id'];
		}
	}
	//Initialisation 1ère date
	$week = date('W');
	if (date('w') == 6 || date('w') == 0) $week ++;
	$weekAfficheImmediat = $week - 32;
	if ($weekAfficheImmediat <= 0) $weekAfficheImmediat += 52;
?>
	<body onload="updateEDT();displayTime();<?php if (isset($id)){ echo "recupJours($weekAfficheImmediat); for (var i = 0; i<5; i++) recupEdtJour(i);";}?>">
		<div id="divSession"><?php $session=-1 ; $time=-1; include("recupSession.php");?></div>
		<div id="selectionEDT">
			Section :
			<?php 
				//echo "test ID 2 ".$id;
				if (isset($id) && $id != "")
				{
					//echo "SELECT composante.id from composante JOIN section on section.idComposante = composante.id WHERE section.id = $id;";
					$donneesComposanteAvecId = mysql_query("SELECT composante.id from composante JOIN section on section.idComposante = composante.id WHERE section.id = $id;") or die(mysql_error());
					//echo "test3";
					$resultComposante = mysql_fetch_array($donneesComposanteAvecId);
					if ($resultComposante){
						//echo "SELECT section.id, section.nom from section where (visible = 1 or id=".$id.") AND idComposante=".$resultComposante['id']." order by nom";
						$donnees = mysql_query("SELECT section.id, section.nom from section where (visible = 1 or id=".$id.") AND idComposante=".$resultComposante['id']." order by nom");
					} 
				}
				$donneesComposante = mysql_query("SELECT * from composante");
				
				$test = false;
			?>
			<select id="selectComp">
				<option value='-1'>Choisissez votre composante</option>
				<?php
					
					while ($result = mysql_fetch_array($donneesComposante))
					{
						echo "<option value=\"".$result['id']."\" ";
						if (isset($resultComposante) && $resultComposante['id'] == $result['id'])
						{
							echo "selected=\"selected\"";
							$test = true;
						}
						echo " >".$result['nom']."</option>"; // (id :".$result['id'].")
					}
				?>
			</select>
			<select id="selectRes" <?php if (!isset($id)) echo "disabled"; ?>>
				<option value="-1">Choisissez votre section</option>
				<?php
					
					if (isset($id))
					{
						if ($resultComposante)
						{
							while ($result = mysql_fetch_array($donnees))
							{
								echo "<option value=\"".$result['id']."\" ";
								if (isset($id) && $id == $result['id'])
								{
									echo "selected=\"selected\"";
									$test = true;
								}
								echo " >".$result['nom']."</option>"; // (id :".$result['id'].")
							}
						}
						if (!$test && isset($id))
							echo "<option value='".$id."' selected='selected'>".$id."</option>";
					}
				?>
			</select>
			<span id="ical"> Calendrier au format iCal : <input type="text" value="" size="50" id="icallink" /></span>
			<br/>
			Semaine : <input type='button' id='btnSemainePrecedente' value='&lt;&lt;' /><!-- semaine pr&eacute;c&eacute;dente -->
			<select id="selectionDate">
				<?php 
				
				for ($i = -3; $i < 10; $i++)
				{
					if ($i+$week <= 52)
					{
						if ($i + $week <= 0)
							$weekAffiche = $i+$week +52;
						else
							$weekAffiche = $i+$week;
					}
					else
					{
						$weekAffiche = $i+$week-52;
					}
					
					$weekEDT = $weekAffiche - 32;
					if ($weekEDT <= 0) $weekEDT += 52;
					echo "<option value=\"$weekEDT\" ";
					if ($i==0) echo "selected=\"selected\"";
					echo ">";
					if ($i==0) echo "- ";
					echo "$weekAffiche";
					if ($i==0) echo " -";
					echo "</option>";
					
					//pour après
					if ($i == 0)
						$weekAfficheImmediat = $weekEDT;
				}
			?>
			</select>
			<input type='button' id='btnSemaineSuivante' value='&gt;&gt;' /> <!-- semaine suivante -->
		</div>
		<div id="zoneEDT">
			<div id="heures">
				<div style="margin-top:25px;">8h</div>
				<?php 
					for ($i = 0; $i< 10; $i++)
					{
						echo "<div style=\"margin-top:40px;\">".($i+9)."h</div>";
					}
				?>
			</div>
			<div id="heuresTrait">
				<div style="margin-top:51px; height:0px; border-bottom: 1px dotted #A0A0A0;"></div>
				<div style="margin-top:14px; height:0px; border-bottom: 1px dashed grey;"></div>
				<div style="margin-top:14px; height:0px; border-bottom: 1px dotted #A0A0A0;"></div>
				<div style="margin-top:14px; border-bottom: 2px solid black;"></div>
				<?php 
					for ($i = 0; $i< 9; $i++)
					{
						echo "<div style=\"margin-top:14px; height:0px; border-bottom: 1px dotted #A0A0A0;\"></div>";
						echo "<div style=\"margin-top:14px; height:0px; border-bottom: 1px dashed grey;\"></div>";
						echo "<div style=\"margin-top:14px; height:0px; border-bottom: 1px dotted #A0A0A0;\"></div>";
						echo "<div style=\"margin-top:13px; border-bottom: 2px solid black;\"></div>";
					}
				?>
				<div style="margin-top:14px; height:0px; border-bottom: 1px dotted #A0A0A0;"></div>
				<div style="margin-top:15px; height:0px; border-bottom: 1px dashed grey;"></div>
				<div style="margin-top:14px; height:0px; border-bottom: 1px dotted #A0A0A0;"></div>
			</div>
			<div id="joursEtEDT">
				<div id="joursEDT">
					<div class="jour">Lundi</div>
					<div class="jour">Mardi</div>
					<div class="jour">Mercredi</div>
					<div class="jour">Jeudi</div>
					<div class="jour">Vendredi</div>
				</div>
				<div id="edt">
					<?php 
					 
					
					for ($i = 0; $i<5; $i++)
						echo "<div class='day' id='jour".$i."'></div>";
					
					/*if (isset($id))
					{
						echo "<script type='text/javascript'>recupJours($weekAfficheImmediat); for (var i = 0; i<5; i++) recupEdtJour(i); </script>";
					}*/
					mysql_close();
					?>
				</div>
			</div>
		</div>
		<div id='loading' class='infosCours'><img class='infosCours' src='images/loading.gif' alt='loading'/></div>
		<div id='infosCours' class='infosCours'></div>
		<div id='trait_heure'><hr/></div>
	</body>
</html>
	
	
	
	
	
	
	
	
	
	
	
	